package com.boarsoft.boar.office.group	.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.boarsoft.bean.ReplyInfo;
import com.boarsoft.boar.common.Constants;
import com.boarsoft.boar.office.entity.OfficeGroup;
import com.boarsoft.boar.office.group.OfficeGroupBiz;
import com.boarsoft.common.Authorized;
import com.boarsoft.common.Util;
import com.boarsoft.common.dao.PagedResult;

@Component
@RestController
@RequestMapping("/group")
public class OfficeGroupAction {
	@Autowired
	private OfficeGroupBiz officeGroupBiz;

	@RequestMapping("/list.do")
	@Authorized(code = "work.group.list")
	public ReplyInfo<Object> list(String key, int pageNo, int pageSize, String orderBy) {
		PagedResult<OfficeGroup> pr = officeGroupBiz.list(key, pageNo, pageSize, orderBy);
		return new ReplyInfo<Object>(true, pr);
	}

	@RequestMapping("/save.do")
	@Authorized(code = "work.group.save")
	public ReplyInfo<Object> save(OfficeGroup o) {
		if (Util.strIsEmpty(o.getId())) {
			return this.add(o);
		}
		return this.update(o);
	}

	@RequestMapping("/add.do")
	@Authorized(code = "work.group.add")
	public ReplyInfo<Object> add(OfficeGroup o) {
		if (officeGroupBiz.add(o)) {
			return ReplyInfo.SUCCESS;
		}
		return Constants.REPLY_INFO_DUPLICATED;
	}

	@RequestMapping("/update.do")
	@Authorized(code = "work.group.update")
	public ReplyInfo<Object> update(OfficeGroup o) {
		if (officeGroupBiz.update(o)) {
			return ReplyInfo.SUCCESS;
		}
		return Constants.REPLY_WARN_INVALID;
	}

	@RequestMapping("/delete.do")
	@Authorized(code = "work.group.delete")
	public ReplyInfo<Object> delete(String id) {
		officeGroupBiz.delete(id);
		return ReplyInfo.SUCCESS;
	}
}